<?php
namespace app\admin\model;


use think\Db;
use think\Request;
use app\admin\model\Base;


class Courses extends Base{

    //课程管理首页
    public function index(){

        $res = Db::table('courses')
            ->alias('co')
            ->join('users u','co.user_id = u.user_id')
//            ->join('courseclassify c','co.classify_id = c.classify_id')
            ->order('courses_id asc')
            ->select();

        return $res;
    }

    //课程删除
    public function cuorsesDelete()
    {
        $request = Request::instance()->get();
        $id = $request['id'];
        $fid = $request['fid'];

        if($fid == 1){
            Db::table('courses')->where('courses_id', $id)->update(['courses_del' => '0']);
            return 0;
        }else if ($fid == 0){
            Db::table('courses')->where('courses_id', $id)->update(['courses_del' => '1']);
            return 0;
        }


    }

    //课程修改获取信息
    public function update(){

        $request = Request::instance()->get();
        $id = $request['id'];


        $cuorsesFind = Db::table('courses')
            ->alias('co')
            ->join('users u','co.user_id = u.user_id')
//            ->join('courseclassify c','co.classify_id = c.classify_id')
            ->where("Courses_id = $id")
            ->find();
        return $cuorsesFind;

    }

    //课程修改
    public function cuorsesUpdate(){
        $request = Request::instance()->post();

        $data = array();
        $data['courses_id'] = $request['courses_id'];
        $data['courses_name'] = $request['courses_name'];
        $data['courses_title'] = $request['courses_title'];
        $data['courses_money'] = $request['courses_money'];

        $res = Db::table('courses')->update($data);

        return $res;
    }

    //图片上传
    public function uploadImg(){

        $res = $this->upload();
        return $res;

    }

    //视频上传
    public function video(){
        $res = $this->video_Upload();
        return $res;
    }




    //课程新增
    public function cuorsesInsert(){
        $request = Request::instance()->post();

        $data = array();
        $data['courses_name'] = $request['courses_name'];
        $data['courses_title'] = $request['courses_title'];
        $data['courses_content'] = $request['courses_content'];
        $data['classify_id'] = $request['classify_id'];
        $data['courses_photo'] = $request['courses_photo'];
        $data['courses_money'] = $request['courses_money'];
        $data['user_id'] = 1;
        $data['courses_del'] = 2;
        $data['courses_time'] = time();

        $res = $this->add("courses",$data);

        return $res;



    }

}